package 泛型;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class MyClass<T> {

    public void printType() {
        // 获取父类的泛型类型
        Type type = getClass().getGenericSuperclass();

        if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;
            Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
            for (Type t : actualTypeArguments) {
                System.out.println(t.getTypeName());
            }
        }
    }
}

